
var api = require('../../utils/api.js');
var app = getApp();
Page({
    data: {
        tophe:0,
        over:0,
        avatar:''
    },
    currentPageNumber: 1,
        onLoad() {
        var file=api.FIlE;
        this.setData({
            bg:file
        })
        var that=this;
        api.post({
            url: 'user/index',
            data: {},
            success: data => {
                that.setData({
                    user:data.data,
                    avatar:data.data.avatar
                });
            },
        });
    },
    onShow() {
        let jn = wx.getMenuButtonBoundingClientRect();
        var that=this;
        console.log(jn);
        var tophe=jn.top+jn.height;
        var over =tophe+230 ;
        this.setData({
            tophe:tophe,
            over:jn.top
        })

       
        
     
    },

    getimgs(){
        let that = this;
        var usrl=api.HOST;

        wx.chooseMedia({
          count: 1,
          mediaType:['image'],
          sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
          sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
          success: function (res) {
            console.log(res)
      
            // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
            let file = res.tempFiles;
            var token=wx.getStorageSync('token')
         
            wx.uploadFile({
              filePath: file[0].tempFilePath,
              name: 'file',
              url: usrl+'common/upload',
              header: {
                'token': token 
              },
              success:function(res){
                var data= JSON.parse(res.data);
                that.setData({
                  avatar:data.data.fullurl
                });
        
              },
              fail: function (res) {
                console.log('上传失败');
                }
            })
          }
        })
    },
    back(){
        wx.switchTab({
          url: '/pages/my/my',
        })
    }

});
